{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 5.3: Sparsity Benchmark\n",
    "\n",
    "## Hardware Specification for Rerun\n",
    "\n",
    "Desktop workstation with 2x (AMD EPYC 7702 64-Core) with total of 128 physical and 256 logical cores, 1024 GB DDR4 with Ubuntu 22.04 LTS operating system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ASO Sparsity for g='15' np.mean(sparsity)=92.00%, np.std(sparsity)=4.42%\n",
      "PRUNED Sparsity for g='15' np.mean(sparsity)=86.65%, np.std(sparsity)=6.49%\n",
      "ASO Sparsity for g='10' np.mean(sparsity)=91.60%, np.std(sparsity)=4.60%\n",
      "PRUNED Sparsity for g='10' np.mean(sparsity)=86.03%, np.std(sparsity)=6.74%\n",
      "ASO Sparsity for g='07' np.mean(sparsity)=91.54%, np.std(sparsity)=4.66%\n",
      "PRUNED Sparsity for g='07' np.mean(sparsity)=85.92%, np.std(sparsity)=6.78%\n"
     ]
    }
   ],
   "source": [
    "import molli as ml\n",
    "import h5py\n",
    "import numpy as np\n",
    "\n",
    "for g in \"15\", \"10\", \"07\":\n",
    "    with h5py.File(f\"bpa_aligned_grid{g}_aso.hdf5\") as f:\n",
    "        descriptors = np.asarray([f[k] for k in f.keys()])\n",
    "        sparsity = 1 - np.count_nonzero(descriptors, axis=1) / descriptors.shape[1]\n",
    "        print(\n",
    "            f\"ASO Sparsity for {g=} {np.mean(sparsity)=:.2%}, {np.std(sparsity)=:.2%}\"\n",
    "        )\n",
    "\n",
    "    with h5py.File(f\"bpa_aligned_grid{g}.hdf5\") as f:\n",
    "        N = f[\"grid\"].shape[0]\n",
    "        pruned_grp = f[\"grid_pruned_idx\"]\n",
    "        sparsity = 1 - np.asarray(\n",
    "            [pruned_grp[k].shape[0] / N for k in pruned_grp.keys()]\n",
    "        )\n",
    "        print(\n",
    "            f\"PRUNED Sparsity for {g=} {np.mean(sparsity)=:.2%}, {np.std(sparsity)=:.2%}\"\n",
    "        )"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "dev-blake",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
